﻿using MyAspx.EasyFramework.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyAspx.EasyFramework.DAL3
{
    public class UserDAL
    {
        commyaspxdbEntities _myaspxentities = new commyaspxdbEntities();
        public string ValidateUser(my_users _my_users)
        {
            if (_myaspxentities.my_users.Count(
                                                 p => p.useregname == _my_users.useregname &&
                                                 p.userpwd == _my_users.userpwd)
                                                 > 0)
                return "find";

            else
                return "nofind";
        }
        //public int AddUser(my_users _my_users)
        //{
        //    var pUser = _my_manage.adminname;
        //    var pPwd = _my_manage.adminpwd;
        //    if (_myaspxentities.my_manage.Count(SELECT => SELECT.adminname == pUser) > 0)
        //    {
        //        return -1;
        //    }
        //    _myaspxentities.my_manage.Add(new MyAspx.EasyFramework.EntityFramework.my_manage()
        //    {
        //        adminname = pUser,
        //        adminpwd = pPwd
        //    });
        //    _myaspxentities.SaveChanges();
        //    return 1;
        //}
        public my_users HasEqualsUserName(string sName)
        {
            var _myusersobject = from _mymo in _myaspxentities.my_users where _mymo.useregname.Equals(sName) select _mymo;
            if (_myusersobject.Count() > 0)
                return new my_users() { useregname = sName };
            else
                return null;
        }

        public int getUserid(string un)
        {
          return   _myaspxentities.my_users.First(u => u.useregname == un).userid;
        }
    }
}
